<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">



            <ui:define name="content">

                <h:form id="form1">
                    <f:view beforePhase="#{manageInvoiceManagedBean.initView}"> 
                        <p:commandLink style="margin-top:10px;margin-left:20px;position:relative;float:left; height:5px; width:300px;" value="Commence Dunning Email" action="#{manageInvoiceManagedBean.sendDunningEmail}"/>
                        <p:commandLink style="margin-top:10px; margin-left:600px;" value ="View All Invoice" action="#{manageInvoiceManagedBean.viewAll}"/>
                        <div style="height:475px; overflow: auto;">
                        <p:panel style="margin-top:20px;" header="Invoice Detail">
                            <h:outputText style="color:red; font-size:15px;" value="The Invoice Is Abolished" rendered="#{manageInvoiceManagedBean.invoice.abolished}"/>  
                            <h:outputText style="color:green; font-size:15px;" value="The Receipt Has Been Issued" rendered="#{manageInvoiceManagedBean.receiptIssued}"/> 
                            <h:panelGrid columns ="2" cellpadding="3">
                                <h:outputText style="color:blue; font-size:13px;" value ="Payment is Needed" rendered ="#{manageInvoiceManagedBean.isPaymentneed}"/> 
                                <h:outputText value ="" rendered ="#{manageInvoiceManagedBean.isPaymentneed}"/> 
                                <h:outputText style="color:green; font-size:13px;" value ="Payment Cleaned" rendered ="#{!manageInvoiceManagedBean.isPaymentneed}"/> 
                                <h:outputText value ="" rendered ="#{!manageInvoiceManagedBean.isPaymentneed}"/> 
                                <h:outputText value="Invoice Id:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.id}"/> 
                                <h:outputText value="Issued By:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.employeeName}"/> 
                                <h:outputText value= "Issuing Date"/> 
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.issuing_date}"> 
                                <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                </h:outputText>
                                <h:outputText value= "Due Date"/> 
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.dueDate}"> 
                                <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                </h:outputText>
                                <h:outputText style="color:red;" value="Expired" rendered="#{manageInvoiceManagedBean.idDued}"/>
                                 <h:outputText value="" rendered="#{manageInvoiceManagedBean.idDued}"/>   
                                <h:outputText value="InvoiceType:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.invoiceType}"/> 
                                <h:outputText value= "Amount Payable:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.amountPayable}"/> 
                                <h:outputText value= "Payment Balance:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.payment_balance}"/> 
                                <h:outputText value= "Amount Paid:"/>
                                <h:outputText value="#{manageInvoiceManagedBean.invoice.amountPaid}"/>
                            </h:panelGrid>
                        </p:panel>
                        <p:fieldset legend="Delivery Order Info" toggleable="true" toggleSpeed="500"  
                                    toggleListener="#{manageInvoiceManagedBean.handleToggle}"  
                                    onToggleUpdate="deliveryInfo" collapsed="true">  

                            <p:dataTable style ="margin-top:10px;" value ="#{manageInvoiceManagedBean.formDeliveryOrderList()}" var="o">
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="DeliveryOder #" />
                                    </f:facet>
                                    <h:outputText value="#{o.id}" />
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Line Item"/>
                                        </f:facet>
                                        <p:commandLink value="Show" onclick="dlg2.show()"/>
                                        <p:dialog header="DelvieryOrder LineItemList" widgetVar="dlg2" resizable="true" width="500">  
                                            <p:dataTable value="#{manageInvoiceManagedBean.dLineItem}" var="lineItem">
                                                <p:column>
                                                    <f:facet name="header">Product</f:facet>
                                                    #{lineItem.product.productName}
                                                </p:column>  
                                                <p:column>
                                                    <f:facet name="header">Quantity</f:facet>
                                                    #{lineItem.quantity}
                                                </p:column>  
                                                <p:column>
                                                    <f:facet name="header">Unit Price</f:facet>
                                                    #{lineItem.price}
                                                </p:column>  
                                                <p:column>
                                                    <f:facet name="header">Total Price</f:facet>
                                                    #{lineItem.cumAmount}
                                                </p:column>  

                                            </p:dataTable>   
                                        </p:dialog>  
                                </p:column>    
                                <p:column>
                                    <f:facet name="header">Delivery Date</f:facet>
                                    <h:outputText value="#{o.deliveryDate}">
                                        <f:convertDateTime pattern ="dd/MM/yyyy"/>
                                    </h:outputText>    
                                </p:column>

                                <p:column>
                                    <f:facet name="header">Delivery Location</f:facet>
                                    <h:outputText value="#{o.shippingAddress.streetName},"/>
                                    <h:outputText value="#{o.shippingAddress.city}"/>
                                </p:column> 
                            </p:dataTable> 

                        </p:fieldset>  
                        <p:commandButton style="margin-top:10px;" value="Update Payment" onclick="dlg.show()"/><br/>
                        <p:commandButton style="margin-top:50px; " value="Abolish Invoice" onclick="confirmation.show()" rendered="#{!manageInvoiceManagedBean.invoice.abolished}"/> 
                        <p:commandButton style="margin-top:50px;" value="Remove" action="#{manageInvoiceManagedBean.removeInvoice}" rendered="#{manageInvoiceManagedBean.invoice.abolished}"/>
                        <p:commandButton style="margin-left:800px;position:relative;" value="Issue Receipt" update="message" action="#{manageInvoiceManagedBean.issueReceipt}"/>

                        <p:messages id="message"/>




                        <p:confirmDialog message="Are you sure to abolish the invoice?"  
                                         showEffect="bounce" hideEffect="explode"  
                                         header="Abolish Invoice" severity="alert" widgetVar="confirmation">  

                            <p:commandButton value="Yes Sure" update="form1" ajax="true" oncomplete="confirmation.hide()"  
                                             action="#{manageInvoiceManagedBean.abolishInvoice}" />  
                            <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   

                        </p:confirmDialog>
                        <p:dialog header="Fill in Amount Paid by Customer" widgetVar="dlg" resizable="false">  


                            <h:panelGrid columns="2" style="margin-bottom:10px">  
                                <h:outputText value="Amount:" />  
                                <p:inputText value="#{manageInvoiceManagedBean.paymentAmount}" />  
                            </h:panelGrid>  

                            <p:commandButton value="Submit" ajax="false" action="#{manageInvoiceManagedBean.updatePayment}" update="form1" oncomplete="dlg.hide();"/>  


                        </p:dialog> 
                        </div>
                    </f:view>  
                </h:form>

            </ui:define>


        </ui:composition>

    </body>
</html>
